<template>
  <div>
    <div class="report-nav">
      <div
        class="report-nav__item"
        v-for="(t, index) in enumAnalyType"
        :key="t.value"
        :class="{ active: analyType === index }"
        @click="handleTypeChange(index)"
      >
        <div class="report-nav__item-bar"></div>
        <div class="report-nav__item-icon"><i :class="t.icon"></i></div>
        <span class="ml-1">{{ t.label }}</span>
      </div>
    </div>

    <transition name="component-fade" mode="out-in">
      <keep-alive>
        <router-view></router-view>
      </keep-alive>
    </transition>
  </div>
</template>

<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      enumAnalyType: [
        { label: '项目统计', value: 0, name: 'analyProject', icon: 'fa fa-tasks' },
        { label: '产业统计', value: 1, name: 'analyIndustry', icon: 'fa fa-bar-chart' },
        { label: '金额统计', value: 2, name: 'analyFunds', icon: 'fa fa-jpy' },
        { label: '银行统计', value: 3, name: 'analyBank', icon: 'fa fa-university' },
        // { label: '产品统计', value: 4, name: 'analyProduct', icon: 'fa fa-pie-chart' },
        { label: '客户分布', value: 5, name: 'analyCustomer', icon: 'fa fa-sitemap' },
        { label: '代偿分析', value: 6, name: 'analyComp', icon: 'fa fa-pie-chart' },
      ],
      analyType: 0,
    }
  },
  computed: {
    isSidebarCollapse() {
      return !this.$store.getters.sidebar.collapse
    },
  },
  watch: {},
  created() {
    this.initSelect()
  },
  mounted() {},
  methods: {
    initSelect() {
      const { name } = this.$route
      const routeIndex = this.enumAnalyType.findIndex(it => it.name === name)
      this.analyType = routeIndex > -1 ? routeIndex : 0
    },
    handleTypeChange(index) {
      this.analyType = index
      this.$router.replace({
        name: this.enumAnalyType[index].name,
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.report-nav {
  display: flex;
  margin-bottom: 1rem;
  background-color: #fff;
  border: 1px solid $border-color;
  border-radius: $border-radius;
  box-shadow: 0px 1px 4px rgba(192, 192, 192, 0.3);
}
.report-nav__item {
  flex: 1 1 0%;
  position: relative;
  padding: 0.75rem 2rem;
  font-size: 1rem;
  color: $gray-600;
  font-weight: bold;
  transition: all 0.25s ease-out;
  text-align: center;
  cursor: pointer;

  &:hover {
    color: var(--primary);
  }

  &:not(:first-child)::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 1px;
    height: 70%;
    transform: translateY(-50%);
    background-image: linear-gradient(
      to bottom,
      rgba(255, 255, 255, 0) 0%,
      $gray-300 50%,
      rgba(255, 255, 255, 0) 100%
    );
  }

  &.active {
    color: var(--primary);

    .report-nav__item-bar {
      background-color: var(--primary);
    }
  }
}
.report-nav__item-icon {
  font-size: 1.2rem;
}
.report-nav__item-bar {
  position: absolute;
  width: 100%;
  height: 2px;
  left: 50%;
  bottom: -1px;
  transform: translateX(-50%);
  background-color: transparent;
}

.component-fade-enter-active,
.component-fade-leave-active {
  transition: opacity 0.2s ease;
}
.component-fade-enter,
.component-fade-leave-to {
  opacity: 0;
}
.analy-type-title {
  font-weight: bold;
  font-size: 1.15rem;
}
</style>
